﻿var myMask;
function PrintOrder(order_id) {
    Ext.MessageBox.confirm("询问", '确定打印订单？', function(btn) {
        if (btn == "yes") {
            myMask = new Ext.LoadMask(Ext.getBody(), {
                msg: "正在获取数据，请稍候..."
            });
            myMask.show();
            var strUrl = strPath + 'GGFW/DocumentsManage/OrderCommand.fwf?Method=GetViewOrdersInfo';
            Ext.Ajax.request({
                url: strUrl,
                method: 'POST',
                params: {
                    order_id: order_id
                    , start: 0
                    , limit: 500
                },
                failure: function(response, options) {
                    ReturnValue = Ext.MessageBox.alert("警告", "网络异常或登录过期，请重新登录！");
                    myMask.hide();
                },
                success: function(response, options) {
                    var json = response.responseText;
                    var obj = parseJsonResult(json);
                    if (!obj.Success) {
                        showMessage("错误！", "打印出错！请查看详细原因。", obj.Message);
                        myMask.hide();
                    }
                    else {
                        if (obj.totalCount < 1) {
                            showMessage("提示", "打印出错！没有数据！", "打印出错！没有数据！");
                            myMask.hide();
                            return;
                        }
                        GGFWOrderPreview(obj.Records, obj.totalCount);
                    }
                }
            });
        }
    });
}

function GGFWOrderPreview(Records, totalCount) {
    LODOP.PRINT_INIT("斯瑞泰_订单打印_A4纵向");

    /*表格横线L1*/
    var L_begin_t = 29;   /*坚向起始点*/
    var L_begin_l = 11;   /*横向起始点*/
    var L_space_t = 10.5;   /*坚向间隔*/
    var L_space_l = 175;  /*横向长度*/

    var i = 0, j = 0;
    var L_t = 0;

    for (i = 0; i < 25; i++) {
        L_t = L_begin_t + i * L_space_t + "mm";
        LODOP.ADD_PRINT_LINE(L_t, L_begin_l + "mm", L_t, L_begin_l + L_space_l + "mm", 0, 1);
    }

    /*表格竖线*/
    var L1_space_l = 24;
    var L2_space_l = L1_space_l + 34;
    var L3_space_l = L2_space_l + 86;
    var L4_space_l = L3_space_l + 16;

    LODOP.ADD_PRINT_LINE(L_begin_t + "mm", L_begin_l + L1_space_l + "mm", L_t, L_begin_l + L1_space_l + "mm", 0, 1);
    LODOP.ADD_PRINT_LINE(L_begin_t + "mm", L_begin_l + L2_space_l + "mm", L_t, L_begin_l + L2_space_l + "mm", 0, 1);
    LODOP.ADD_PRINT_LINE(L_begin_t + "mm", L_begin_l + L3_space_l + "mm", L_t, L_begin_l + L3_space_l + "mm", 0, 1);
    LODOP.ADD_PRINT_LINE(L_begin_t + "mm", L_begin_l + L4_space_l + "mm", L_t, L_begin_l + L4_space_l + "mm", 0, 1);

    /*固定头部*/
    LODOP.SET_PRINT_STYLE("FontSize", 22);
    LODOP.SET_PRINT_STYLE("Bold", 1);
    LODOP.ADD_PRINT_TEXT("10mm", "78mm", "60mm", "30mm", "订  单  表");

    LODOP.SET_PRINT_STYLE("FontSize", 13);

    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "13mm", "40mm", "12mm", "订单号(PO)：");
    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "80mm", "40mm", "12mm", "客户名：");
    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "130mm", "40mm", "12mm", "日期(DATE)：");

    LODOP.ADD_PRINT_TEXT(L_begin_t + 3 + "mm", "18mm", "20mm", "12mm", "编号");
    LODOP.ADD_PRINT_TEXT(L_begin_t + 3 + "mm", "48mm", "20mm", "12mm", "款名");
    LODOP.ADD_PRINT_TEXT(L_begin_t + 3 + "mm", "100mm", "60mm", "12mm", "颜 色/数 量");
    LODOP.ADD_PRINT_TEXT(L_begin_t + 3 + "mm", "158mm", "20mm", "12mm", "总数");
    LODOP.ADD_PRINT_TEXT(L_begin_t + 3 + "mm", "174mm", "20mm", "12mm", "备注");

    /*打印订单内容*/

    LODOP.SET_PRINT_STYLE("Bold", 0);

    var font_height = "6mm";
    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "40mm", "42mm", font_height, Records[0].order_po);
    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "97mm", "34mm", font_height, Records[0].client_name);
    LODOP.ADD_PRINT_TEXT(L_begin_t - 6 + "mm", "158mm", "32mm", font_height, Records[0].order_date.dateFormat('Y-m-d'));
    for (j = 0; j < totalCount && j < 23; j++) {
        var txt_t = L_begin_t + (j + 1) * L_space_t + 3 + "mm";
        var txt_t1 = L_begin_t + (j + 1) * L_space_t + 0.5 + "mm";
        LODOP.ADD_PRINT_TEXT(txt_t, L_begin_l + 1 + "mm", "20mm", font_height, Records[j].code);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.ADD_PRINT_TEXT(txt_t, L_begin_l + L1_space_l + 1 + "mm", "32mm", font_height, Records[j].pro_name);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.ADD_PRINT_TEXT(txt_t1, L_begin_l + L2_space_l + 1 + "mm", "82mm", font_height, Records[j].color_num + "LineSpaciLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingLineSpacingng");
        //LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.SET_PRINT_STYLEA(0, "LineSpacing", -8);
        LODOP.ADD_PRINT_TEXT(txt_t, L_begin_l + L3_space_l + 1 + "mm", "14mm", font_height, Records[j].total);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
        LODOP.ADD_PRINT_TEXT(txt_t, L_begin_l + L4_space_l + 1 + "mm", "14mm", font_height, Records[j].memo);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
    }
    myMask.hide();
    //打印预览
    LODOP.PREVIEW();
}